<?php
include "config.php";
$querys = "truncate table jalur";
$adds = mysql_query($querys);
$results = mysql_query("SELECT count(*) FROM `transport`");
$rows = mysql_fetch_row($results);
$nos = $rows[0];

for ($i = 1; $i <= $nos; $i++) {
$result = mysql_query("SELECT Nama_File FROM `transport` where id =$i");
$row = mysql_fetch_row($result);
$jalur = $row[0];


$xml = simplexml_load_file("jalur/".$jalur);
$stop = "0";
$status = 1;
foreach($xml->children() as $child)
  {
	//echo $child->getName() . ": " . $child . "<br />";
		foreach($child->children() as $child2)
		{
			//echo $child2->getName() . ": " . $child2 . "<br />";
			
			foreach($child2->children() as $child3)
			{
				//echo $child3->getName() . ": " . $child3. "<br />";
					foreach($child3->children() as $child4)
					{
						if ($child4->getName() == coordinates && $stop == "0"){
							//echo $child4. "<br />";
							$stop = "1";
							$tok = strtok($child4, " \n\t");

							while ($tok !== false) {
								$tok2 = strtok($child4, ",");
								
								while ($tok2 !== false) {
									if($tok2 !== "0") {
										echo "$tok2<br />";
										if ($status == 1) {
										$query = "INSERT INTO jalur (idt, lng, status) VALUES ($i, $tok2, 1)";
										$add = mysql_query($query);
										$status = $status+1;
										} else {
										$query = "update jalur set lat = $tok2, status = 0 where status = 1";
										$status = $status-1;
										$add = mysql_query($query);
										}
										
										
									}
									$tok2 = strtok(" ,\n\t");
								}
								$tok = strtok(" \n\t");
							}
						}
					}
			}
		}
  }
  
  }
?> 